package com.yzc.poi;

import com.yzc.Eqlil.zhaun;
import com.yzc.dao.Zengjai;
import com.yzc.dao.imp.zengim;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.DateUtil;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class yu {

    // 读取，全部sheet表及数据
    public static void showExcel() throws Exception {
        HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(new File("C:\\Users\\Thinkbook\\Documents\\Tencent Files\\3097089520\\FileRecv\\批量导入模板.xls")));
        HSSFSheet sheet = null;
        for (int i = 0; i < workbook.getNumberOfSheets(); i++) {// 获取每个Sheet表
            sheet = workbook.getSheetAt(i);
            for (int j = 1; j < sheet.getLastRowNum() + 1; j++) {// getLastRowNum，获取最后一行的行标
                HSSFRow row = sheet.getRow(j);
                if (row != null) {
                    Object obj[]=new Object[5];
//                    for (int k = 0; k < row.getLastCellNum(); k++) {// getLastCellNum，是获取最后一个不为空的列是第几个
                    System.out.println(row.getLastCellNum());
                        obj[0]=row.getCell(0);
                        obj[1]=row.getCell(1);
                        obj[2]=row.getCell(2);
                        obj[3]=row.getCell(3);
                        obj[4]=row.getCell(4);
                    Zengjai zengjai=new zengim();
                    zengjai.exezeng(obj);
                    if(row.getLastCellNum()>5){
                        for (int o=5;o<row.getLastCellNum();o++){
                           List<zhaun>list=zengjai.cha(row.getCell(1));
                            zengjai.xuan(row.getCell(o),list.get(0).getId());
                        }
                    }
                }
                System.out.println(""); // 读完一行后换行
            }
            System.out.println("读取：" + workbook.getSheetName(i) + " 完成");
        }
    }
}
